package net.mikoo.seals.biz.manager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import net.mikoo.seals.biz.mapper.LinkageMapper;
import net.mikoo.seals.model.Linkage;
import net.mikoo.seals.model.LinkageQuery;

@Component
public class LinkageManager {
	
	private Logger logegr = LoggerFactory.getLogger(LinkageManager.class);

	public static Map<String,Linkage>  _map = new HashMap<String, Linkage>();
	
	@Autowired
	private LinkageMapper linkageMapper;

	@PostConstruct
	public void init() {
		logegr.info("start init Linkage data");
		LinkageQuery query = new LinkageQuery();
		List<Linkage> linkages = linkageMapper.selectListByQuery(query);
		for (Linkage linkage : linkages) {
			_map.put(linkage.getLinkageType().concat(linkage.getValue()), linkage);
			logegr.info(logegr.toString());
		}
		
		logegr.info("end init Linkage data");
	}
	
	public Linkage getLinkage(String type, String key) {
		Linkage linkage = _map.get(type.concat(key));
		return linkage;
	}

}
